<?php

use app\admin\model\AppGpuPrice;
use app\Request;
use think\facade\Db;
use think\facade\Route;
use think\facade\View;

Route::get('/', function (Request $request) {



    $list_type = [];

    foreach (AppGpuPrice::SELECT_LIST_TYPE as  $type_value => $type_title) {


        $list_order = [];

        $list_order = AppGpuPrice::withJoin(['appGpu'])
            ->field([
                Db::raw('app_gpu_price.price / appGpu.cuda_count as cost_price')
            ])
            ->where('type', $type_value)
            ->order('cost_price', 'asc')
            ->limit(20)
            ->select();

        $list_type[] = [
            'title' => $type_title,
            'value' => $type_value,
            'list_order' => $list_order,

        ];
    }


    View::assign('list_type', $list_type);

    return View::fetch('welcome', [
        'data'    => [
            'description'        => '收集和整理的显卡CUDA性价比计算系统。<br>根据设置的报价，计算每颗CUDA核心的性价比。<br>可以扩展升级，实现更多的性价对比，比如功耗、显存等。',

        ],
        'navbar'  => [
            [
                'name'   => '首页',
                'active' => true,
                'href'   => 'http://admin.demo.ulthon.com',
                'target' => '_self',
            ],

            [
                'name'   => '开源地址',
                'active' => false,
                'href'   => 'https://gitee.com/augushong/cuda-compare',
                'target' => '_blank',
            ],
        ],

    ]);
});


Route::rule('/price/:id', function ($id) {


    $model_price = AppGpuPrice::find($id);

    View::assign('model_price', $model_price);

    return View::fetch('price');
});
